package com.smart.oil.service.impl;

import com.alibaba.fastjson.JSON;
import com.smart.oil.entity.SmOiUser;
import com.smart.oil.mapper.SmOiUserMapper;
import com.smart.oil.service.HomeService;
import com.smart.oil.vo.respond.HomeRespVO;
import com.smart.oil.vo.respond.PermissionRespNodeVO;
import com.smart.oil.vo.respond.UserInfoRespVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/** @Author yangxinxin
 * @Description //TODO
 * @Date 21:53 2020/4/7
 * @Param
 * @return
 **/
@Service
public class HomeServiceImpl  implements HomeService {
    /*
    根据用户id查询
     */
    @Autowired
    private SmOiUserMapper  smOiUserMapper;

    @Override
    public HomeRespVO getHome(String userId) {
        HomeRespVO homeRespVO=new HomeRespVO();
/**
 * mock 导航菜单数据后期直接从DB获取
 */
    String home = "[\n" +
            "    {\n" +
            "        \"children\": [\n" +
            "            {\n" +
            "                \"children\": [\n" +
            "                    {\n" +
            "                        \"children\": [\n" +
            "                            {\n" +
            "                                \"children\": [\n" +
            "                                    {\n" +
            "                                        \"children\": [],\n" +
            "                                        \"id\": \"6\",\n" +
            "                                        \"title\": \"五级类目5-6\",\n" +
            "                                        \"url\": \"string\"\n" +
            "                                    }\n" +
            "                                ],\n" +
            "                                \"id\": \"5\",\n" +
            "                                \"title\": \"四级类目4- 5\",\n" +
            "                                \"url\": \"string\"\n" +
            "                            }\n" +
            "                        ],\n" +
            "                        \"id\": \"4\",\n" +
            "                        \"title\": \"三级类目3- 4\",\n" +
            "                        \"url\": \"string\"\n" +
            "                    }\n" +
            "                ],\n" +
            "                \"id\": \"3\",\n" +
            "                \"title\": \"二级类目2- 4\",\n" +
            "                \"url\": \"string\"\n" +
            "            }\n" +
            "        ],\n" +
            "        \"id\": \"2\",\n" +
            "        \"title\": \"类目1\",\n" +
            "        \"url\": \"string\"\n" +
            "    },\n" +
            "    {\n" +
            "        \"children\": [],\n" +
            "        \"id\": \"1\",\n" +
            "        \"title\": \"类目2\",\n" +
            "        \"url\": \"string\"\n" +
            "    }\n" +
            "]";
          // String home="[{\"children\":[{\"children\":[{\"children\":[{\"children\":[{\"children\": [],\"id\":\"6\",\"title\":\"五级类目5-6\",\"url\":\"string\"}],\"id\":\"5\",\"title\":\"四级类目4- 5\",\"url\":\"string\"}],\"id\":\"4\",\"title\":\"三级类目3- 4\",\"url\":\"string\"}],\"id\":\"3\",\"title\":\"二级类目2- 3\",\"url\":\"string\"}],\"id\":\"1\",\"title\":\"类目1\",\"url\":\"string\"},{\"children\": [],\"id\":\"2\",\"title\":\"类目2\",\"url\":\"string\"}]";
    //   String home="[{\"children\":[{\"children\":[{\"children\":[{\"children\":[{\"children\":[],\"id\":\"6\",\"title\":\"五级类目5-6\",\"url\":\"string\"}],\"id\":\"5\",\"title\":\"四级类目4-5\",\"url\":\"string\"}],\"id\":\"4\",\"title\":\"三级类目3-4\",\"url\":\"string\"}],\"id\":\"3\",\"title\":\"二级类目2-3\",\"url\":\"string\"}],\"id\":\"1\",\"title\":\"类目1\",\"url\":\"string\"},{\"children\":[],\"id\":\"2\",\"title\":\"类目2\",\"url\":\"string\"}]";
//                String home="[\n" +
//                "    {\n" +
//                "        \"children\": [\n" +
//                "            {\n" +
//                "                \"children\": [],\n" +
//                "                \"id\": \"3\",\n" +
//                "                \"title\": \"菜单权限管理\",\n" +
//                "                \"url\": \"/index/menus\"\n" +
//                "            }\n" +
//                "        ],\n" +
//                "        \"id\": \"1\",\n" +
//                "        \"title\": \"组织管理\",\n" +
//                "        \"url\": \"string\"\n" +
//                "    },\n" +
//                "    {\n" +
//                "        \"children\": [],\n" +
//                "        \"id\": \"2\",\n" +
//                "        \"title\": \"类目2\",\n" +
//                "        \"url\": \"string\"\n" +
//                "    }\n" +
//                "]";
//        String home="[\n" +
//                " {\n" +
//                " \"children\": [\n" +
//                " {\n" +
//                " \"children\": [],\n" +
//                " \"id\": \"3\",\n" +
//                " \"title\": \"菜单权限管理\",\n" +
//                " \"url\": \"/index/menus\"\n" +
//                " }\n" +
//                " ],\n" +
//                " \"id\": \"1\",\n" +
//                " \"title\": \"组织管理\",\n" +
//                " \"url\": \"string\"\n" +
//                " },\n" +
//                " {\n" +
//                " \"children\": [],\n" +
//                " \"id\": \"2\",\n" +
//                " \"title\": \"类目2\",\n" +
//                " \"url\": \"string\"\n" +
//                " }\n" +
//                "]";
       /*
            拿到首页菜单的数据
        */
        List<PermissionRespNodeVO> list = JSON.parseArray(home,PermissionRespNodeVO.class);
        homeRespVO.setMenus(list);

        SmOiUser smOiUser  = smOiUserMapper.selectByPrimaryKey(userId);//查询
        UserInfoRespVO vo = new UserInfoRespVO();
        if (smOiUser != null){
            BeanUtils.copyProperties(smOiUser,vo);
//
//            vo.setId(smOiUser.getUserId());
//            vo.setUsername(smOiUser.getUsername());
            vo.setDeptName("西安石油大学油田开发实验室");
        }
        homeRespVO.setUserInfoVO(vo);
        return homeRespVO;
    }
}
/*
1。控制层通过调用服务层，拿到菜单数据以及首页导航的头部的数据
 */